<template>
  <div>
    <el-dialog :visible="updateDialog" title="编辑学科" width="400px" @close="onClose">
      <el-form :model="tagsForm" :rules="rules">
        <el-form-item label="所属学科" prop="subjectID">
          <el-select v-model="tagsForm.subjectID" placeholder="请选择">
            <el-option
                v-for="item in subjectsSimple"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称" prop="tagName">
          <el-input v-model="tagsForm.tagName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onClose()">取 消</el-button>
        <el-button type="primary" @click="tagsAdd">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { updateTags } from '../../api/hmmm/tags'

export default {
  name: 'updateTags',
  props: {
    updateDialog: {
      type: Boolean,
      required: true
    },
    subjectsSimple: {
      type: Array,
      required: true
    },
    tagsForm: {
      type: Object,
      required: true
    },
    isShow: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      //  验证规则
      rules: {
        tagName: [
          { required: true, message: '请输入要添加的目录名称', trigger: 'blur' }
        ]
      },
      tagForm: {
        tagName: '',
        subjectID: '',
        id: ''
      }
    }
  },
  created () {
  },
  methods: {
    // 父组件传过来赋值
    // 关闭弹框事件
    onClose () {
      this.$emit('update:tagsForm', {})
      this.$emit('update:updateDialog', false)
      this.$emit('update:isShow', false)
    },
    // 弹框提交事件
    async tagsAdd () {
      await updateTags(this.tagsForm)
      this.$message.success('添加成功')
      this.$emit('update:updateDialog', false)
      this.$emit('loadDirectorsList')
      this.$emit('update:isShow', false)
    }
  }
}
</script>

<style lang='less' scoped>
.el-form {
  padding-bottom: 10px;

  .el-input {
    width: 200px;
  }
}
</style>
